package algorithm.leetcode.I201to400;

public class Q299 {

    public String getHint(String secret, String guess) {
        byte[] need = new byte[10], offer = new byte[10];
        int cows = 0, bulls = 0;

        for (int i = 0; i < secret.length(); i++) {
            if (secret.charAt(i) == guess.charAt(i)) bulls++;
            else {
                offer[guess.charAt(i)-'0']++;
                need[secret.charAt(i)-'0']++;
            }
        }

        for (int i = 0; i < need.length; i++) {
            cows += Math.min(need[i], offer[i]);
        }
        return bulls+"A"+cows+"B";
    }

}
